package com.axing.aiguideagent.controller;

import com.axing.aiguideagent.agent.AxingManus;
import com.axing.aiguideagent.app.GuideApp;
import jakarta.annotation.Resource;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.tool.ToolCallback;
import org.springframework.http.codec.ServerSentEvent;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import reactor.core.publisher.Flux;

import java.io.IOException;

@RestController
@RequestMapping("ai")
public class AiController {

    @Resource
    private GuideApp guideApp;

    @Resource
    private ToolCallback[] allTools;

    @Resource
    private ChatModel dashcopeChatModel;

    /**
     * SSE流式调用AI心理咨询师应用
     *
     * @param message
     * @param chatId
     * @return
     */
    @GetMapping("/guide_app/chat/sse")
    public Flux<String> doChatWithLoveAppSSE(String message, String chatId) {
        return guideApp.doChatByStream(message, chatId);
    }

    /**
     * 流式调用Manus超级智能体
     *
     * @param message
     * @return
     */
    @GetMapping("/manus/chat")
    public SseEmitter doChatWithManus(String message) {
        AxingManus axingManus = new AxingManus(allTools, dashcopeChatModel);
        return axingManus.runStream(message);
    }
}